package com.base.component.ai.platform.prompt;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.component.ai.platform.AudioCompletionsHandler;
import com.base.component.ai.platform.core.bo.common.AudioCompletionsBO;
import com.gitee.magic.core.exception.ApplicationException;

/**
 * 组件服务
 * 
 * @author zywei
 *
 */
@Service
public class PromptTemplateAudioService {

	@Autowired
	private List<AudioCompletionsHandler> audioCompletionsHandler;
	
	/**
	 * 获取所有支持的模型
	 * @return
	 */
	public List<String> getSupportModel(){
		List<String> models=new ArrayList<>();
		for(AudioCompletionsHandler handler:audioCompletionsHandler) {
			models.addAll(handler.getSupportModel());
		}
		return models;
	}
	
	public void execute(AudioCompletionsBO param,Consumer<String> process) {
		for(AudioCompletionsHandler handler:audioCompletionsHandler) {
			if(handler.support(param.getModel())) {
				handler.execute(param,(c)->{
					process.accept(c);
				});
				return;
			}
		}
		throw new ApplicationException("找不到执行模型："+param.getModel() +" code:"+param.getCode());
	}
	
}
